<?php
$sitemap_dir = 'tpl/Web/resource/sitemap/';
require 'attach/function.php';
manager_config(require_once 'attach/config.php');

$uri = $_SERVER['REQUEST_URI'];
$uri = trim($uri,'/');
if($uri == 'sitemap.xml') {
    $conn = mysql_connect( manager_config('db_host').":".manager_config('db_port'), manager_config('db_username'), manager_config('db_password') );
    mysql_select_db( manager_config('db_select') );
    mysql_query( "set names ".manager_config('code') );
    $res = mysql_query('select token from '.manager_config('table_name').' where domain = "' . $_SERVER['HTTP_HOST'] . '"', $conn);
    $row = mysql_fetch_assoc($res);
    $path = $sitemap_dir . $row['token'] . '.xml';
    if(file_exists($path)) {
        $content = file_get_contents($path);
        //$content = htmlspecialchars_decode($content);
        header("Content-type: text/xml; charset=utf8");
        echo $content;
    }else{
        echo '请访问主页<a href="/" >网站首页</a>';
    }
    exit;
}
?>

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>404错误页面</title>
</head>
<body>

    <div style="text-align: center;margin-top:200px;font-size:20px;">请按照正常渠道访问</div>
    <div style="text-align: center;font-size:20px;"><a href='http://<?php echo $_SERVER['HTTP_HOST']; ?>'>网站首页</a></div>

</body>
</html>